/**
 * Created by xinhuang on 15/6/11.
 */

'use strict';
describe('单元测试: chartService 服务', function () {
  beforeEach(module('services.customActivity.realtime'));

  var chartService;
  beforeEach(inject(function ($injector) {
    chartService = $injector.get('chartService');
  }));

  describe('分时刻业务量: chartService.busTimeVol', function () {

    var options;
    beforeEach(function () {
      chartService.busTimeVol.init(
        document.createElement('div'),
        'upay',
        {xAxis: '08:00:00', data: [111, 111]}
      );
    });

    it('init() 生成实例', function () {
      options = chartService.busTimeVol.instance.upay.getOption();

      expect(options.xAxis[0].data.length).toBe(24);
      expect(options.xAxis[0].data[22]).toEqual('');
      expect(options.xAxis[0].data[23]).toEqual('08:00:00');
      expect(options.series[0].data.length).toBe(24);
      expect(options.series[0].data[1]).toEqual(0);
      expect(options.series[0].data[23]).toEqual(111);
      expect(options.series[1].data.length).toBe(24);
      expect(options.series[1].data[1]).toEqual(0);
      expect(options.series[1].data[23]).toEqual(111);
    });

    it('update() 更新图表', function () {
      chartService.busTimeVol.update('upay', {xAxis: '08:00:05', data: [112, 113]});
      options = chartService.busTimeVol.instance.upay.getOption();

      expect(options.xAxis[0].axisLabel.interval).toBe(2);
      expect(options.xAxis[0].data.length).toBe(24);
      expect(options.xAxis[0].data[23]).toEqual('08:00:05');
      expect(options.series[0].data.length).toBe(24);
      expect(options.series[0].data[23]).toBe(112);
      expect(options.series[1].data.length).toBe(24);
      expect(options.series[1].data[23]).toBe(113);
    });
  });

  describe('用户充值偏好 userRechargePrefer', function () {

    var options;

    beforeEach(function () {
      chartService.userRechargePrefer.init(
        document.createElement('div'),
        'upay',
        {yAxis: ['(0,5]', '(5,20]', '(20,50]'], data: [11, 111, 1111]}
      );
    });

    it('init() 生成实例', function () {
      options = chartService.userRechargePrefer.instance.upay.getOption();

      expect(options.yAxis[0].data).toEqual(['(0,5]', '(5,20]', '(20,50]']);
      expect(options.series[0].data).toEqual([11, 111, 1111]);
    });

    it('update() 更新图表', function () {
      chartService.userRechargePrefer.update('upay', [111, 112, 1121]);
      options = chartService.userRechargePrefer.instance.upay.getOption();

      expect(options.series.length).toBe(1);
      expect(options.series[0].data).toEqual([111, 112, 1121]);
    });
  });

  describe('分省业务量/成功率 province', function () {

    var options;

    beforeEach(function () {
      chartService.province.init(
        document.createElement('div'),
        'busProVol',
        [
          {provinceName: '广东', volume: 98.0, volState: 0},
          {provinceName: '江西', volume: 97.0, volState: 0},
          {provinceName: '湖南', volume: 96.0, volState: 0},
          {provinceName: '浙江', volume: 95.0, volState: 1},
          {provinceName: '上海', volume: 94.0, volState: 1},
          {provinceName: '北京', volume: 93.0, volState: 1}
        ]
      );
    });

    it('init() 生成实例', function () {
      options = chartService.province.instance['busProVol'].getOption();

      expect(options.series.length).toBe(3);
      expect(options.series[1].data.length).toBe(3);
      expect(options.series[1].data[0]).toEqual({name: '广东', value: 98.0});
      expect(options.series[2].data.length).toBe(3);
      expect(options.series[2].data[0]).toEqual({name: '浙江', value: 95.0});
    });

    it('update() 更新图表', function () {
      chartService.province.update(
        'busProVol',
        [
          {provinceName: '广东', volume: 97.0, volState: 0},
          {provinceName: '江西', volume: 96.0, volState: 0},
          {provinceName: '湖南', volume: 95.0, volState: 0},
          {provinceName: '浙江', volume: 94.0, volState: 1},
          {provinceName: '上海', volume: 93.0, volState: 1},
          {provinceName: '北京', volume: 92.0, volState: 1}
        ]);
      options = chartService.province.instance['busProVol'].getOption();

      expect(options.series[1].data[0]).toEqual({name: '广东', value: 97.0});
      expect(options.series[2].data[0]).toEqual({name: '浙江', value: 94.0});
    });
  });
});